package event

import (
	"context"
	"ez/apps/erp/auto/mc"
	erp "ez/apps/erp/document"
	"ez/apps/tool/service"
	"ez/custom/cc"
	"gitee.com/dreamwood/ez-go/ez"
	"time"
)

func init() {
	ez.Subscribe(mc.InquiryEventBeforeCreate, func(v interface{}, ctx context.Context) {
		md, ok := v.(*erp.Inquiry)
		if ok {
			uid := cc.GetUidFromCtx(ctx)
			md.CreateEmpId = uid
			if md.FormEmpId == 0 {
				md.FormEmpId = uid
				md.FormAt = time.Now()
			}

			if md.Sn == "" {
				md.Sn = service.CreateSnByString(ez.ConfigService.AppId,
					"CGXJ-[YY][MM][DD]-[DMAX[3]]", 1)
			}
		}
	})
}
